package presentation;

import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.Color;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.border.Border;

public class Menu extends JPanel {
	/**
     * 
     */
    private static final long serialVersionUID = 1L;
    
    PanelConteneur pc;
    
    //bouton contenu dans le panel
    private JButton jbAquarium=new JButton();
    private JButton jbPoisson=new JButton();
    private JButton jbPlante=new JButton();
    private JButton jbMesure=new JButton();
    

    // Cadres 
    private Border border1 = BorderFactory.createLineBorder(Color.black);

    public Menu(PanelConteneur jpc){
            
            this.pc=jpc;
            
            this.setBackground(Color.WHITE);
            this.setLayout(new BorderLayout());
            
            JPanel jp_haut = new JPanel(new GridLayout(1,5));
            
            jp_haut.setOpaque(false);
            
            //Cadre 
            jp_haut.setBorder(BorderFactory.createTitledBorder(border1,"Gestion des aquariums "));
            
            jp_haut.add(jbAquarium);
            jp_haut.add(jbPoisson);
            jp_haut.add(jbPlante);  
            jp_haut.add(jbMesure);
            
            jbAquarium.setIcon(new ImageIcon("images/aquarium.gif"));
            jbAquarium.setFocusPainted(false);
            jbAquarium.setContentAreaFilled(false);
            
            jbPoisson.setIcon(new ImageIcon("images/poisson.gif"));
            jbPoisson.setFocusPainted(false);
            jbPoisson.setContentAreaFilled(false);
            
            jbPlante.setIcon(new ImageIcon("images/plante.gif"));
            jbPlante.setFocusPainted(false);
            jbPlante.setContentAreaFilled(false);
            
            jbMesure.setIcon(new ImageIcon("images/mesure.gif"));
            jbMesure.setFocusPainted(false);
            jbMesure.setContentAreaFilled(false);
            
            this.add(jp_haut,BorderLayout.CENTER);
            
            jbAquarium.addActionListener(new MonActionListener());
            jbPoisson.addActionListener(new MonActionListener());
            jbPlante.addActionListener(new MonActionListener());
            jbMesure.addActionListener(new MonActionListener());
    
    }
    
    
    class MonActionListener implements ActionListener{

            @Override
            public void actionPerformed(ActionEvent ae) {
                    if(ae.getSource() == jbAquarium){
                            CardLayout cl = (CardLayout)(pc.getLayout());
                    cl.show(pc, "CreerAquarium");
                    }
                    
                    if(ae.getSource() == jbPoisson){
                            CardLayout cl = (CardLayout)(pc.getLayout());
                    cl.show(pc, "CreerPoisson");

                    }
                    
                    if(ae.getSource() == jbPlante){
                            CardLayout cl = (CardLayout)(pc.getLayout());
                    cl.show(pc, "CreerPlante");
                    }
                    
                    if(ae.getSource() == jbMesure){
                            CardLayout cl = (CardLayout)(pc.getLayout());
                    cl.show(pc, "CreerMesure");
                    }
                    
            }               
    }
}
